package org.ydsw.data.manage.mapper;

import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import org.ydsw.data.manage.entity.ScheduleJobEntity;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

/**
 * @author admin
 */
@Repository
public interface ScheduleJobEntityMapper extends Mapper<ScheduleJobEntity> {

    /**
     * 新增任务实例
     * @param scheduleJobEntity
     * @return
     */
    int insertScheduleJobEntity(ScheduleJobEntity scheduleJobEntity);

    @Update({ "update schedule_job set create_time = now(),backup_status='备份成功' where  method_name = 'backUpData' and params = #{params}" })
    int updateBackupTime(String params);

    @Update({ "update schedule_job set create_time = now() where  method_name = #{method_name}" })
    int updateCreateTime(String method_name);

    @Select({ "select params from schedule_job where method_name = 'dealMaxStorage'" })
    @Results(
            id = "maxStorage",
            value = {
                    @Result(property = "params",column = "params"),
            }
    )
    List<ScheduleJobEntity>  selectMaxStorage();

    @Update({ "update schedule_job set remark='正常' where  method_name = 'dataManageNGForceChControl'" })
    int updateChStatusNormal();
    @Update({ "update schedule_job set remark='clickhouse存储已达上限,日志关闭接收' where  method_name = 'dataManageNGForceChControl'" })
    int updateChStatusAbnormal();

    @Update({ "update schedule_job set remark='正常' where  method_name = 'dataManageNGForceKafkaControl'" })
    int updateKafkaStatusNormal();
    @Update({ "update schedule_job set remark='kafka缓存已达上限,日志关闭接收' where  method_name = 'dataManageNGForceKafkaControl'" })
    int updateKafkaStatusAbnormal();


    //查询已有的备份任务
    @Select("select method_name,remark from schedule_job where method_name = 'dataManageNGForceKafkaControl' or method_name = 'dataManageNGForceChControl'")
    @Results(
            id = "remark",
            value = {
                    @Result(property = "methodName",column = "method_name"),
                    @Result(property = "remark",column = "remark"),
            }
    )
    List<ScheduleJobEntity>  selectMethodRemark();


}
